﻿using GenericHtml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.Json;
using WLFramework.Web;

namespace SampleSite.admin.ajax
{
    /// <summary>
    /// getUserPosition 的摘要说明
    /// </summary>
    public class getUserPosition : AjaxHttpHandler
    {
        public override void OnProcessRequest(HttpContext context)
        {
            int? uid = context.GetValueByName<int?>("U_ID");
            if (uid == null)
                return;

            using (var db = new PermissionContext())
            {
                var users = db.View_UserPosition.Where(k => k.U_ID == uid);

                context.Response.Write(JSON.Instance.ToJSON(new
                {
                    total = users.Count(),
                    rows = users.OrderByDescending(k => k.IsMain)
                    .Select(k => new
                    {
                        U_ID = k.U_ID,
                        P_ID = k.P_ID,
                        P_State = k.P_State == 0 ? "禁用" : "启用",
                        IsMain = k.IsMain == true ? "主要" : "次要",
                        O_CName = k.O_CName,
                        O_EName = k.O_EName,
                        P_CName = k.P_CName,
                        P_EName = k.P_EName
                    }).ToList()
                }));
            }
        }
    }
}